#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define ERROR -999

typedef int Position;
typedef int ElementType;
typedef struct DSNode* PtrToDSNode;
struct DSNode
{
    ElementType* Data; 
    Position Top1; 
    Position Top2;
    int MaxSize;  
};
typedef PtrToDSNode DStack;

DStack MakeEmpty(int MaxSize)
{
    DStack DS = (DStack) malloc(sizeof(struct DSNode));
    DS->Data = (ElementType*) malloc(MaxSize * sizeof(ElementType));
    DS->Top1 = -1;
    DS->Top2 = MaxSize;
    DS->MaxSize = MaxSize;
    return DS;
}

bool Push(DStack DS, ElementType X, int Tag) // Tag为1表示第一个堆栈，2表示第二个堆栈
{
    if (DS->Top2 - DS->Top1 == 1) {
        printf("堆栈满\n");
        return false;
    }

    if (Tag == 1) {
        DS->Data[++(DS->Top1)] = X;
    } else {
        DS->Data[--(DS->Top2)] = X;
    }
    return true;
}

ElementType Pop(DStack DS, int Tag)
{
    if (Tag == 1) {
        if (DS->Top1 == -1) {
            printf("堆栈1空\n");
            return ERROR;
        }
        return DS->Data[(DS->Top1)--];
    } else {
        if (DS->Top2 == DS->MaxSize) {
            printf("堆栈2空\n");
            return ERROR;
        }
        return DS->Data[(DS->Top2)++];
    }
}

int main()
{
    DStack DS = MakeEmpty(5);
    Push(DS, -1, 1);
    Push(DS, -2, 1);
    Push(DS, -3, 1);
    Push(DS, 10, 2);
    Push(DS, 11, 2);
    Pop(DS, 1);
    Pop(DS, 1);
    for (int i = 0; i <= DS->Top1; i++) {
        printf("%d ", DS->Data[i]);
    }
    printf("\n");
    for (int i = DS->Top2; i < DS->MaxSize; i++) {
        printf("%d ", DS->Data[i]);
    }
    return 0;
}